package liuch.reflection;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Hello world!
 */
public class Reflection {
    private String a;

    public static void main(String[] args) {
        Object b = new Reflection();
        Class<?> clazz = b.getClass();
        BeanInfo bInfo = null;
        try {
            bInfo = Introspector.getBeanInfo(clazz);
        } catch (IntrospectionException ignored) {
        }

        if (bInfo != null) {
            for (PropertyDescriptor pd : bInfo.getPropertyDescriptors()) {

                Method writeMethod = pd.getWriteMethod();
                if (writeMethod == null) {
                    continue;
                }


                Method readMethod = pd.getReadMethod();
                if (readMethod != null) {
                    try {
                        if (readMethod.invoke(b) != null) {
                            continue;
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e.getMessage(), e);
                    }
                }

                Class<?> mdpBeanClass = pd.getPropertyType();
                Class<?> interfaceClazz = (Class<?>) ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments()[0];
                Type type = clazz.getGenericSuperclass();
                int l = ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments().length;
            }
        }
    }
}
